local youxing = fk.CreateSkill{
    name = "ym2__youxing",
}
Fk:loadTranslationTable{
    ["ym2__youxing"] = "忧行",
    [":ym2__youxing"] = "出牌阶段每种牌名限一次，你可以重铸一张基本牌，然后重铸对你可见的一张牌。失去伤害牌或武器牌的角色须选择明置一张伤害牌或获得一张不计入手牌上限的【影】。",
    ["#ym2__youxing"] = "忧行：重铸一张基本牌",
    ["#ym2__youxing-target"] = "忧行：重铸一名角色区域内一张对你可见的牌",
    ["#ym2__youxing-card"] = "忧行：重铸 %dest 区域内一张对你可见的牌",
    ["#ym2__youxing-show"] = "忧行：明置一张伤害牌，或获得一张不计入手牌上限的【影】",
    ["@@ym2__youxing-inhand"] = "忧行",
    ["$ym2__youxing1"] = "后宅女子万不可僭越干预朝政啊。",
    ["$ym2__youxing2"] = "今兄弟互伐，姊妹相残，是何理也？！",
}
local U = require "packages/utility/utility"
youxing:addEffect("active",{
    prompt = "#ym2__youxing",
    anim_type = "control",
    card_num = 1,
    card_filter = function (self, player, to_select, selected)
        local card = Fk:getCardById(to_select)
        local mark = player:getTableMark("ym2__youxing-phase")
        return #selected == 0 and card.type == Card.TypeBasic and not table.contains(mark,card.trueName)
    end,
    target_num = 0,
    target_filter = Util.FalseFunc,
    on_use = function (self, room, effect)
        local player = effect.from
        local loser = {}
        local mark = player:getTableMark("ym2__youxing-phase")
        table.insertIfNeed(mark,Fk:getCardById(effect.cards[1]).trueName)
        room:setPlayerMark(player,"ym2__youxing-phase",mark)
        if table.find(effect.cards,function (cardID)
            local card = Fk:getCardById(cardID)
            return card.is_damage_card or card.sub_type == Card.SubtypeWeapon
        end) then
            table.insert(loser,player)
        end
        room:recastCard(effect.cards,player,youxing.name)
        local targets = {}
        for _, tp in ipairs(room.alive_players) do
            if table.find(tp:getCardIds("hej"),function (cardID)
                return player:cardVisible(cardID)
            end) then
                table.insert(targets,tp)
            end
        end
        if #targets > 0 then
            local tos = room:askToChoosePlayers(player,{
                max_num = 1,
                min_num = 1,
                targets = targets,
                skill_name = youxing.name,
                prompt = "#ym2__youxing-target",
                cancelable = false,
            })
            local to = tos[1]
            local cards1, cards2, cards3 = table.filter(to:getCardIds("h"),function (cardID)
                return player:cardVisible(cardID)
            end), table.filter(to:getCardIds("e"),function (cardID)
                return player:cardVisible(cardID)
            end), table.filter(to:getCardIds("j"),function (cardID)
                return player:cardVisible(cardID)
            end)
            local card_data = {}
            if #cards1 > 0 then
                table.insert(card_data,{"$Hand",cards1})
            end
            if #cards2 > 0 then
                table.insert(card_data,{"$Equip",cards2})
            end
            if #cards3 > 0 then
                table.insert(card_data,{"$Judge",cards3})
            end
            local card = room:askToChooseCard(player, {
                target = to,
                flag = { card_data = card_data },
                skill_name = youxing.name,
                prompt = "#ym2__youxing-card::"..to.id,
                cancelable = false,
            })
            if Fk:getCardById(card).is_damage_card or Fk:getCardById(card).sub_type == Card.SubtypeWeapon then
                table.insert(loser,to)
            end
            room:recastCard({card},to,youxing.name)
        end
        if #loser > 0 then
            for _, tp in ipairs(loser) do
                local ids = table.filter(tp:getCardIds("he"),function (cardID)
                    return Fk:getCardById(cardID).is_damage_card
                end)
                local cards = room:askToCards(player,{
                    max_num = 1,
                    min_num = 1,
                    pattern = tostring(Exppattern{id = ids}),
                    cancelable = true,
                    skill_name = youxing.name,
                    prompt = "#ym2__youxing-show",
                })
                if #cards > 0 then
                    room:setCardMark(Fk:getCardById(cards[1]), "@@ShownCards-inhand", 1)
                else
                    room:obtainCard(tp,U.getShade(room,1),true,fk.ReasonJustMove,player,youxing.name,"@@ym2__youxing-inhand")
                end
            end
        end
    end,
})
youxing:addEffect("maxcards", {
    exclude_from = function (self, player, card)
        return card:getMark("@@ym2__youxing-inhand") ~= 0
    end,
})
return youxing